package com.example.tidycalendartest;

import java.util.Date;
import android.database.sqlite.*;

public class Event {
	protected Integer categoryId;
	protected Integer eventId;
	
	protected String description;
	protected String name;
	
	protected Date startDate;
	protected Date endDate;
	
	public Event(String name, String desc, int categoryId, Date startDate, Date endDate)
	{
		this.name = name;
		this.description = desc;
		this.categoryId = categoryId;
		this.eventId = 1;
		this.startDate = startDate;
		this.endDate = endDate;
	}

	/*
	//Commented out data validation
	public boolean isValidStartDate(Date d)
	{
		if (startDate.after(endDate)) {
			return false;
		}
		
		return true;
	}
	*/
	
	
	/*
	 * Create a new row in the database with this event's data
	 */
	public boolean create(SQLiteDatabase db)
	{
		
		
		return false;
	}
	
	/*
	 * Update an existing row in the database with this event's data
	 */
	
	public boolean update(SQLiteDatabase db)
	{
		return false;
	}
	
	/*
	 * Getters and setters
	 */
	
	//CatagoryId is set by user to specify the event category 
	public Integer getCategoryId() {
		return this.categoryId;
	}

	public boolean setCategoryId(Integer id)
	{
		if (id < 0){
			return false;
		}
		
		this.categoryId = id;
		return true;
	}
	
	// Unique ID for the event for Database
	public Integer getEventId() {
		return this.eventId;
	}
	
	public void setEventId(Integer id)
	{
		// Check/Compare to make sure ID is not already present in Database
		this.eventId = id;
	}
	
	
	public String getDescription()
	{
		return this.description;
	}
	
	// User entered string - Optional 
	public boolean setDescription(String desc)
	{
		if (desc.length() < DatabaseHelper.MAX_DESCRIPTION_FIELD){
			return false;
		}
		
		this.description = desc;
		return true;
	}
	
	public String getName()
	{
		return this.name;
	}
	
	public boolean setName(String name)
	{
		if ((name.length() > DatabaseHelper.MAX_NAME_FIELD) ||
				name.isEmpty()){
			return false;
		}
		
		this.name = name;
		return true;
	}
	
	public Date getStartDate()
	{
		return this.startDate;
	}
	
	// Check that start is not after end
	public boolean setStartDate(Date date)
	{
		if (date.after(this.endDate)){
			return false;
		}
			
		this.startDate = date;
		return true;
	}
	
	public Date getEndDate()
	{
		return this.endDate;
	}
	
	// Check that end is not before start
	public boolean setEndDate(Date date)
	{
		if (date.before(this.startDate)){
			return false;
		}
		
		this.endDate = date;
		return true;
	}
	
}
